package com.jinyuan.options.login;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioGroup;

import com.jinyuan.R;
import com.jinyuan.options.OptionsFragment;
import com.jinyuan.service.MobileApplication;

/**
 * 登陆、注册控制类
 * 
 * @author azuryleaves
 * @since 2014-1-3 下午12:14:29
 * @version 1.0
 * 
 */
public class LoginActivity extends FragmentActivity implements
		LoginTopFragment.Callbacks {

	public static String Position = "position";
	private Button parentdialog_cancel_Button;
	public static Button parentdialog_confirm_Button;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		MobileApplication.allActivity.add(this);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		parentdialog_cancel_Button = (Button) findViewById(R.id.parentdialog_cancel_Button);
		parentdialog_cancel_Button.setOnClickListener(clickListener);
		parentdialog_confirm_Button = (Button) findViewById(R.id.parentdialog_confirm_Button);
		onRadioGroupCheckedChanged(null, R.id.login_tab_1_RadioButton);
	}

	private void toFragment(int position) {
		OptionsFragment.popBackStack(this);
		OptionsFragment fragment = null;
		switch (position) {
		case R.id.login_tab_1_RadioButton:
			fragment = new LoginFragment();
			break;
		case R.id.login_tab_2_RadioButton:
			fragment = new RegisterFragment();
			break;
		default:
			break;
		}
		if (fragment != null) {
			getSupportFragmentManager().beginTransaction()
					.replace(R.id.login_content_FrameLayout, fragment).commit();
		}
	}

	private OnClickListener clickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.parentdialog_cancel_Button:
				finish();
				break;
			default:
				break;
			}
		}
	};

	@Override
	public void onRadioGroupCheckedChanged(RadioGroup radioGroup, int checkedId) {
		toFragment(checkedId);
	}

}
